#!/usr/bin/env python
# encoding: utf-8
'''
@author: liuchong
@contact: lucas@007vin.com
@software: garner
@file: banzhou.py
@time: 2020/8/24 2:44 下午
@desc:
'''

import sys
from multiprocessing import Pool

sys.path.append('../../')
import pandas as pd
import re
from pymongo import MongoClient
import ujson
from models.vwag.vwag import CarsPartNumNew, CarsSaDesc, CarsStructureCollectionNew, Vb
from scripts.fenci import remove_tt
from cars_scripts.service.AudiService import cleanTransmission, cleanDrive, cleanCylinder, cleanPower
from cars_scripts.service.add_date import audi_do_filter_extra_info, mergeDate

s = ['3缸', '三缸', '4缸', '四缸', '5缸', '五缸', '6缸', '六缸', '8缸', '八缸', '10缸', '十缸', '12缸', '十二缸']
qd = ['全轮驱动', '前驱动', '前部驱动', '四轮驱动']
fuel = ['汽油', '柴油']
bsx = ['7档', '7档自动', '7档手动', '7档双离合', '七档', '七档自动', '七档手动', '七档双离合', '6档', '6档自动', '6档手动', '6挡手自一体',
       '六档', '六档自动', '六档手动', '5档', '5档自动', '5档手动', '五档', '五档自动', '五档手动', '5挡手自一体',
       '4档', '4档自动', '4档手动', '四档', '四档自动', '四档手动', '8档', '8档自动', '8档手动', '8挡手自一体',
       '八档', '八档自动', '八档手动', '3档', '3档自动', '3档手动', '三档', '三档自动', '三档手动', '无级自动']
pl = ['1.5', '1.6', '1.1', '1.8', '1.3', '2.0', '2.1', '1.9', '2.4', '1.7', '1.05', '1.2', '1.0', '0.9', '0.8', '2.7', '2.2', '2.23', '2.9', '2.8', '4.3', '2.5', '1.4', '2.3', '3.2', '4.0', '3.0', '4.9', '6.0', '4.2', '5.0', '2.6', '3.6', '3.8']
fdjdm = ['AAK', 'EWA', '122', '124', '126', '127', 'EZA', 'ABS', 'ADD', 'ADZ', 'DTA', 'ABV', 'ADY', 'AAA', 'AAM', 'AAZ', 'AGF', '22R', 'ACL', 'ACT', 'ABN', 'ABX', 'ACB', 'ACD', 'H 1', 'AAB', 'AAC', 'AAF', 'ABL', 'ACU', 'AAU', 'AAV', 'ACM', 'ABD', 'ABF', 'ABU', 'ACX', 'ABA', 'ACC', 'ADC', 'ACV', 'AES', 'AET', 'AEU', 'AHY', 'AJA', 'AJT', 'AMV', 'APL', 'AUF', 'AVT', 'AXG', 'AXL', 'AYC', 'AYY', 'ACR', 'AHP', 'ANL', 'AQM', 'ATK', 'BJG', 'AGG', 'AHU', 'ALE', 'AEK', 'AFN', 'AFT', 'AKR', 'AKS', 'ANN', 'ANP', 'AEP', 'AHA', 'ADX', 'AEA', 'AEE', 'AEF', 'AER', 'AEV', 'AEX', 'AFH', 'AGD', 'AHG', 'AHS', 'AJV', 'AKU', 'AKV', 'ALL', 'ANX', 'APQ', 'AJH', 'AMY', 'ANU', 'AVG', 'AEN', 'AEY', 'AHB', 'ALH', 'AUA', 'AUD', 'AYQ', 'AGK', 'AGL', 'AGX', 'AHD', 'ANJ', 'APA', 'ATA', 'AUH', 'AVR', 'BBE', 'BBF', 'BCQ', 'AEG', 'AEH', 'AGN', 'AGP', 'AGR', 'AGU', 'AGZ', 'AHF', 'AHW', 'AJM', 'AKL', 'AKQ', 'APE', 'APF', 'APK', 'AQA', 'AQN', 'AQP', 'AQY', 'ARL', 'ARZ', 'ASV', 'ASZ', 'ATD', 'ATN', 'AUE', 'AUM', 'AUS', 'AUY', 'AVU', 'AWD', 'AWW', 'AXP', 'AZD', 'AZH', 'AFP', 'AVH', 'AZG', 'APH', 'AVC', 'AWH', 'AWU', 'AWV', 'AXJ', 'AYD', 'ARX', 'ATU', 'AWF', 'AWG', 'ACK', 'ADP', 'ADR', 'AEB', 'AFB', 'AFY', 'AGE', 'AHH', 'AHL', 'AKN', 'ANA', 'ANB', 'APR', 'APT', 'APU', 'AQD', 'ARG', 'ARM', 'ASU', 'ATJ', 'ATX', 'AUZ', 'AVA', 'AVB', 'ALG', 'ALT', 'ALZ', 'AMX', 'ATQ', 'AVF', 'AWM', 'AWT', 'AWX', 'AZM', 'AZX', 'BBG', 'BDN', 'BDP', 'AFK', 'AHT', 'ALD', 'AMF', 'ANM', 'ANV', 'ANY', 'AQQ', 'ARR', 'AUB', 'AUC', 'AVY', 'AYZ', 'BBY', 'AKK', 'ALM', 'ANW', 'AUR', 'AKP', 'ARC', 'ASX', 'ATL', 'AKW', 'ANQ', 'AWL', 'BFF', 'BGC', 'BNL', 'BPZ', 'ATM', 'AWC', 'AYL', 'AFV', 'AFX', 'AGY', 'CPEA', 'CREB', 'CUHA', 'CYPA', 'CYYA', 'DMJA', 'ASY', 'AWY', 'AXR', 'AXU', 'AZQ', 'BAH', 'BAY', 'BBX', 'BBZ', 'BKY', 'BLM', 'BLT', 'BMD', 'BME', 'AJS', 'AYT', 'BAN', 'BGH', 'BGJ', 'BKL', 'BMK', 'BRK', 'BRN', 'BTT', 'AWB', 'BAE', 'BAF', 'BJH', 'AUQ', 'AZJ', 'BAD', 'BCA', 'BCB', 'BDE', 'AWP', 'BBW', 'BDF', 'BEJ', 'BEK', 'BER', 'BEV', 'BEW', 'BHP', 'BFS', 'BKF', 'BNU', 'BCC', 'BCD', 'AXQ', 'AYH', 'AZZ', 'BAA', 'BAC', 'BJN', 'BKJ', 'BKS', 'BLE', 'BLK', 'BMV', 'BMX', 'BRJ', 'AAX', 'ADV', 'AFU', 'AJD', 'BBV', 'BSC', 'BZF', 'ANC', 'ANF', 'ANG', 'ANH', 'BCT', 'BCU', 'BCV', 'BGL', 'BGM', 'BSP', 'BTW', 'CDXA', 'CDXB', 'CEMA', 'CEZA', 'BDC', 'BGD', 'AFZ', 'ASF', 'ASW', 'AZN', 'AZP', 'BJY', 'UDH', 'UNF', 'UPD', 'UQG', 'AFR', 'UGA', 'ARA', 'BPA', 'BGG', 'BHG', 'BJF', 'BJR', 'BNY', 'BSL', 'BTY', 'BJA', 'AQZ', 'BJE', 'BLH', 'BNX', 'CCNA', 'CCRA', 'CFZA', 'BNW', 'BWX', 'CCPA', 'BKR', 'BNM', 'CHFA', 'CHFB', 'CFEA', 'BTJ', 'CBPA', 'CPBA', 'CNBA', 'CSEA', 'BFQ', 'BAU', 'BDG', 'BDH', 'BGW', 'BHW', 'BEH', 'BFH', 'BML', 'BTB', 'AVQ', 'AXW', 'AZV', 'BAG', 'BGU', 'BKC', 'BKD', 'BLF', 'BLP', 'BLR', 'BLX', 'BLY', 'BRU', 'AXA', 'AXB', 'AXC', 'AXD', 'AXE', 'BDL', 'BKK', 'BLJ', 'AFE', 'AYF', 'BSA', 'AJR', 'AYJ', 'BHJ', 'AXX', 'BDK', 'BHY', 'BKG', 'BLN', 'BMM', '262', '496', 'ADF', 'ATE', 'BEF', 'BMF', 'CBSA', '682', '685', '686', '68A', '68C', '68D', 'ADK', '28B', '694', 'ADE', 'ADG', 'AFD', 'ARD', 'AVM', 'BEQ', 'BEU', 'BJC', 'BXT', 'CBKA', '751', '752', '761', 'ACP', 'BBR', 'CBHA', 'CBJB', 'CJDA', 'CJDD', 'CSSA', 'DJNB', 'DJSA', 'DLSA', 'DLWA', 'DMBA', 'CWLA', 'CWVA', 'CXDB', 'CZDA', 'DGXA', 'DJXA', 'DKFA', 'CUGA', 'DBFC', 'DKVB', 'DKXA', 'CSTA', 'DJNA', 'DJRA', 'DLSB', 'DJMA', 'CVMC', 'CVMD', 'CYRB', 'CYRC', 'DCBE', 'DENA', 'DEND', 'DMFA', 'DMVB', 'BDJ', 'BJB', 'BLS', 'BSE', 'BSF', 'BST', 'BSU', 'BSX', 'BUD', 'BJZ', 'BPL', 'CFBA', 'CFUA', 'CGZA', 'CSRA', 'BGP', 'BGQ', 'BPY', 'BRM', 'BTK', 'BWA', 'BXE', 'CAWB', 'CAYB', 'CBDB', 'CBEA', 'CBFA', 'CBTA', 'CBUA', 'CCCA', 'CCTA', 'CJAA', 'BKT', 'BKU', 'BTL', 'CKZA', 'CMR', 'BNZ', 'BPC', 'BRR', 'BRS', 'BRY', 'BEE', 'BLG', 'BMY', 'BVY', 'BVZ', 'BXF', 'AXZ', 'BKP', 'BLV', 'BMA', 'BMP', 'BMR', 'BUZ', 'BVE', 'BVX', 'BWS', 'BWV', 'BBM', 'BBU', 'BJX', 'BMS', 'BMT', 'BNV', 'BTS', 'BWB', 'BZG', 'BMN', 'CAXA', 'CCSA', 'BPR', 'BPS', 'BSW', 'BMB', 'BUB', 'BYD', 'BRT', 'BVH', 'BVK', 'BXJ', 'BAR', 'BHK', 'BHL', 'BPD', 'BPE', 'BUN', 'CBRA', 'BJJ', 'BJK', 'BJL', 'BJM', 'CEBA', 'CEBB', 'CECA', 'CECB', 'BWH', 'BYJ', 'CFB', 'CEDA', 'CHZC', 'CLPA', 'CLPB', 'CLSA', 'CXBA', 'CXBB', 'CXCB', 'BUR', 'UVC', 'DPKA', 'CNXA', 'CWSA', 'CSEZ', 'CWRA', 'CYTA', 'CSEB', 'CYTC', 'DNBA', 'DLFA', 'EBDA', 'DHSB', 'CHZL', 'DADA', 'DGTD', 'DKJA', 'DKLA', 'DKRF', 'DPLA', 'DJZA', 'DUKA', 'CYAA', 'EBHA', 'CNXC', 'CAVD', 'CAWA', 'CAYC', 'CEGA', 'BMG', 'BMH', 'CDDA', 'CDEA', 'BVB', 'CBDA', 'BWF', 'CASA', 'CASB', 'CASC', 'CATA', 'CBWA', 'CFRA', 'CBLA', 'BZB', 'CBAA', 'CBAB', 'CCTB', 'CARA', 'CARB', 'CEXA', 'CGUA', 'CGVA', 'CJRA', 'BWK', 'CAVA', 'CBBA', 'CBBB', 'CCZA', 'CCZC', 'CFFA', 'CFFB', 'CFFD', 'CFGB', 'CLJA', 'CENA', 'CFNA', 'CPJA', 'CEN', 'CBAC', 'CCZB', 'CDAA', 'CDAB', 'CGYA', 'CKMA', 'CLLA', 'CNNA', 'CBDC', 'CBZA', 'CBZB', 'CDLA', 'CDLC', 'CDLF', 'CGGA', 'CHGA', 'CLCA', 'CMXA', 'CFHB', 'CFHC', 'CNWA', 'CFGC', 'CMSB', 'CTHD', 'CTKA', 'CULA', 'CULC', 'CUUB', 'CUWA', 'CUXA', 'CXSB', 'CDVA', 'CDGA', 'CAVB', 'CAVC', 'CFJA', 'CFLA', 'CHNA', 'CAVE', 'CAYA', 'CBZC', 'CFWA', 'CGGB', 'CGPA', 'CGPB', 'CLNA', 'CMAA', 'CNKA', 'CJLA', 'CFNB', 'CAAA', 'CAAB', 'CAAC', 'CAAE', 'CCHA', 'CCHB', 'CFCA', 'CJKA', 'CDBA', 'CDCA', 'CFPA', 'CNEA', 'CNFA', 'CSHA', 'CLCB', 'CDF', 'CGMA', 'CLR', 'CLRA', 'CEAA', 'CFFE', 'CNWB', 'CTHA', 'CAYD', 'CAYE', 'CFHE', 'CFHF', 'CDVB', 'CKRA', 'CPKA', 'CPRA', 'CVCA', 'CKJA', 'CNLA', 'CPLA', 'CPPA', 'CRJA', 'CASD', 'CGEA', 'CGFA', 'CGNA', 'CGRA', 'CJGD', 'CJMA', 'CJTA', 'CKDA', 'CMTA', 'CNRB', 'CRCA', 'CFJB', 'CTHB', 'CTHC', 'CEA', 'CGM', 'CNGA', 'CEXB', 'CMVA', 'CPFA', 'DAHA', 'DLXA', 'DBHA', 'DBJA', 'CUUA', 'CYVD', 'DELA', 'CHPB', 'CJZA', 'CZCA', 'CCZD', 'CUVC', 'CUVE', 'CZDB', 'CKTB', 'CKTC', 'CKUB', 'CKUC', 'CSLA', 'CSLB', 'CSLC', 'CSNA', 'CHYA', 'CHYB', 'CPGA', 'DAFA', 'CDLG', 'CRZA', 'CAAD', 'CJKB', 'CSDA', 'DAGA', 'CUCA', 'CHHA', 'CHHB', 'CHPA', 'CHZD', 'CJXB', 'CJXC', 'CJXD', 'CJXE', 'CJXG', 'CJZB', 'CKFC', 'CLHA', 'CLHB', 'CMBA', 'CNTA', 'CPTA', 'CPVA', 'CPVB', 'CPWA', 'CRBB', 'CRBC', 'CRGA', 'CRKA', 'CRKB', 'CRLB', 'CRMB', 'CRVA', 'CRVC', 'CUKB', 'CUNA', 'CXDA', 'CXSA', 'CXXA', 'CXXB', 'CYFB', 'CYKB', 'CYVA', 'CYVB', 'CZBA', 'CZEA', 'DBKA', 'DEJA', 'DEJB', 'CDLJ', 'CTHE', 'CVWA', 'CNFB', 'CKAA', 'CPDA', 'DCFA', 'CSCA', 'CJSB', 'CRLD', 'CZDD', 'DBVA', 'EABA', 'CHZB', 'CJZC', 'CJZD', 'CUSA', 'CUSB', 'CUTA', 'CWVB', 'CWYA', 'CYZA', 'CYZB', 'DAJA', 'DAJB', 'EAGA', 'EAZA', 'EBSA', 'CHZK', 'DACA', 'DCYA', 'DCYB', 'DDYA', 'DDYB', 'DFGA', 'DGTE', 'DKLB', 'DPBA', 'DPCA', 'CNSA', 'CNSB', 'CRUA', 'CXCA', 'CDLK', 'CZDC', 'CRCD', 'CVVA', 'CYJA', 'CZTA', 'DGMA', 'CJSA', 'CJSC', 'CJXA', 'CUAA', 'CUKC', 'CUPA', 'CZPB', 'DBGA', 'DBGB', 'DCXA', 'DCZA', 'DDAA', 'DFCA', 'DFEA', 'DFGB', 'DFHA', 'DGEB', 'DKZA', 'DNUA', 'DRFA', 'DSRA', 'DSRB', 'CHYD', 'CWXA', 'CWXB', 'CWXC', 'DDSA', 'DASA', 'DASB', 'DASC', 'DAUA', 'DAUB', 'DAVA', 'DAWA', 'CUFA', 'DDKA', 'CZPA', 'DBGC', 'CHZJ', 'DFFA', 'DJKA', 'DNUE', 'CJXH', 'CNTC', 'DGCA', 'DGEA', 'DHFA', 'DJGA', 'DJHA', 'DJHB', 'DJJA', 'DKTB', 'DLBA', 'DLRA', 'DNUC', 'DJHC', 'DLRB', 'CDVC', 'CDVD', 'DCGA', 'DGUA', 'DGVA', 'DNJA', 'DNLA', 'CHYC', 'CZPC', 'DBYA', 'DFNA', 'DFNB', 'DGTC', 'DKZC', 'DSGB', 'CXEB', 'CXEC', 'CXFA', 'CXGA', 'CXGB', 'CXHA', 'CXHB', 'CUVA', 'DEDA', 'DFLA', 'DFLD', 'DFMA', 'DLTA', 'DLTC', 'DLUB', 'CHZG', 'CUUD', 'CUUE', 'CUUF', 'CYVC', 'CZCB', 'DFSB', 'DFSC', 'DFSD', 'DFSE', 'DFSF', 'DJKD', 'DKRD', 'DKRE', 'DHSA', 'DDSB', 'DEKA', 'DFEB', 'DFGC', 'DGDA', 'DKRB', 'CRFD', 'CRGB', 'CYKC', 'DACB', 'DGDB', 'DJVA', 'DKTA', 'DPBE', 'DNCA', 'CHYE', 'CHZA', 'DKLC', 'DKRA', 'DDXA', 'DDXB', 'DDXC', 'DDXD', 'DDXE', 'EBMA', 'CXHC', 'CXGD', 'ABG', 'ATW', 'AUG', 'AXK', 'BAP', 'BRP', 'BKW', 'AMM', 'BJS']
glv = ['37KW', '81KW', '57KW', '38KW', '55KW', '63KW', '51KW', '48KW', '40KW', '66KW', '82KW', '44KW', '85KW', '60KW', '42KW', '70KW', '68KW', '75KW', '43KW', '33KW', '29KW', '25KW', '100KW', '95KW', '53KW', '77KW', '61KW', '50KW', '35KW', '49KW', '32KW', '30KW', '59KW', '56KW', '74KW', '34KW', '18KW', '22KW', '31KW', '46KW', '79KW', '72KW', '89KW', '98KW', '54KW', '64KW', '88KW', '118KW', '62KW', '140KW', '47KW', '125KW', '128KW', '110KW', '103KW', '84KW', '69KW', '78KW', '111KW', '65KW', '150KW', '120KW', '135KW', '142KW', '92KW', '105KW', '80KW', '96KW', '116KW', '130KW', '165KW', '132KW', '202KW', '45KW', '155KW', '220KW', '185KW', '230KW', '177KW', '309KW', '246KW', '331KW', '147KW', '228KW', '162KW', '90KW', '52KW', '108KW', '121KW', '257KW', '195KW', '73KW', '58KW', '67KW', '170KW', '173KW', '71KW', '36KW', '83KW', '169KW', '137KW', '190KW', '183KW', '250KW', '210KW', '180KW', '310KW', '184KW', '206KW', '94KW', '86KW', '176KW', '258KW', '171KW', '148KW', '187KW', '196KW', '112KW', '188KW', '199KW', '191KW', '245KW', '265KW', '213KW', '221KW', '215KW', '136KW', '141KW', '193KW', '235KW', '115KW', '200KW', '175KW', '146KW']
items = []
client = MongoClient('192.168.10.170', 27017)
db = client.standard_label
collection = db.standard_label_unique

audiParts = CarsPartNumNew.select(CarsPartNumNew.brand_code, CarsPartNumNew.cid, CarsPartNumNew.extra_info,
                                  CarsPartNumNew.mid, CarsPartNumNew.model, CarsPartNumNew.pid, CarsPartNumNew.remark,
                                  CarsPartNumNew.sa_code)
def DealParts(i):
    for audiPart in audiParts:
        while i*100 < audiPart.id <= (i+1)*100:
            pid = audiPart.pid
            cid = audiPart.cid
            mid = audiPart.mid
            if 'dropped' not in audiPart.extra_info:
                stand_info = collection.find_one({'pid': pid, 'brandCode': audiPart.brand_code})
                stand_label = stand_info['standard_label'] if stand_info else ''
                if stand_label:
                    # 配置代码
                    sa_codes = []
                    # 发动机排量
                    cylinder = []
                    # 发动机代码
                    vb = []
                    # 发动机排量信息
                    vb_desc = []
                    transmission = []
                    drive = []
                    diff_mech = []
                    energy_type = []
                    power = []
                    pid = audiPart.pid
                    cid = audiPart.cid
                    mid = audiPart.mid
                    stand_info = collection.find_one({'pid': pid, 'brandCode': audiPart.brand_code})
                    stand_label = stand_info['standard_label'] if stand_info else ''
                    # pSacodes = getSacode(audiPart.sa_code)
                    part_sa_codes = audiPart.sa_code or '{}'
                    part_sa_codes = ujson.loads(part_sa_codes)
                    for key, value in part_sa_codes.items():
                        if value:
                            sa_codes = sa_codes + value
                    pModel = audiPart.model.replace('<br/>', '')
                    pRemark = audiPart.remark

                    pModelout = remove_tt(pModel)
                    pRemarkout = remove_tt(pRemark)

                    if pRemark:
                        for key in s:
                            if key in pRemarkout:
                                cy = cleanCylinder(key)
                                cylinder.append(cy)
                        for key in pl:
                            if key in pRemark:
                                vb_desc.append(key)

                    if pModel:
                        for key in bsx:
                            if key in pModelout:
                                tran = cleanTransmission(key)
                                transmission.append(tran)
                        for key in qd:
                            if key in pModelout:
                                dr = cleanDrive(key)
                                drive.append(dr)

                        for key in s:
                            if key in pModelout:
                                mcy = cleanCylinder(key)
                                cylinder.append(mcy)
                        for key in pl:
                            if key in pModel:
                                vb_desc.append(key)
                        for key in fdjdm:
                            if key in pModel:
                                vb.append(key)
                        if 'PR:' in pModel or 'PR-' in pModel or 'pr:' in pModel or 'pr-' in pModel:
                            # 处理part_model中的PR
                            part_pr = re.sub('[\u4e00-\u9fa5]', '', pModel)
                            part_pr = part_pr.replace('PR:', '')
                            part_pr = part_pr.replace('PR-', '')
                            part_pr = part_pr.replace('+', ',')
                            part_pr = part_pr.replace('/', ',')
                            part_pr = part_pr.replace(':', ',')
                            part_pr = part_pr.replace('_', ',')
                            part_pr = part_pr.split(',')
                            for j in part_pr:
                                sa_codes.append(j)

                    sa_codes = set(sa_codes)
                    sa_codes = list(sa_codes)

                    vb = set(vb)
                    vb = list(vb)

                    for i in sa_codes:
                        if cid.startswith('U'):
                            contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid[1:], CarsSaDesc.sa == i,
                                                              CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == audiPart.brand_code)
                        else:
                            contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid, CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh',
                                                              CarsSaDesc.brand_code == audiPart.brand_code)
                        if not contrast:
                            contrast = CarsSaDesc.get_or_none(CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh',
                                                              CarsSaDesc.brand_code == audiPart.brand_code)
                        if contrast and contrast.desc:
                            saDescout = remove_tt(contrast.desc)
                            # model_desc.append(contrast.desc)
                            if '发动机' in contrast.desc:
                                # 筛选出sa表desc中的排量信息
                                for key in pl:
                                    if key in contrast.desc:
                                        vb_desc.append(key)
                                for key in s:
                                    if key in saDescout:
                                        key = cleanCylinder(key)
                                        cylinder.append(key)
                                for key in fuel:
                                    if key in saDescout:
                                        energy_type.append(key)
                                for key in glv:
                                    if key in saDescout:
                                        key = cleanPower(key)
                                        power.append(key)

                            # 处理变速器配置
                            if ('变速箱' in contrast.desc or '变速器' in contrast.desc) and ('档' in contrast.desc or '无级' in contrast.desc):
                                for key in bsx:
                                    if key in saDescout:
                                        key = cleanTransmission(key)
                                        transmission.append(key)

                            # 处理驱动配置
                            for key in qd:
                                if key in saDescout:
                                    key = cleanDrive(key)
                                    drive.append(key)

                            # 处理差速器配置
                            if '差速' in contrast.desc or '减速' in contrast.desc:
                                diff_mech.append(contrast.desc)

                    for i in vb:
                        if cid.isdigit():
                            vb_AF = Vb.get_or_none(Vb.aa == str(int(cid)), Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                        elif cid.startswith('U'):
                            vb_AF = Vb.get_or_none(Vb.aa == cid[1:], Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                        else:
                            vb_AF = Vb.get_or_none(Vb.aa == cid, Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                        if vb_AF:
                            if vb_AF.af:
                                vb_desc.append(str(int(vb_AF.af) / 100))
                            if vb_AF.ai:
                                cylinder.append(vb_AF.ai)
                            if vb_AF.ag:
                                power.append(vb_AF.ag)

                    # 处理part时间
                    date, colorDate, year = audi_do_filter_extra_info(audiPart.extra_info)
                    dateLeft, dateRight = mergeDate(date)
                    colordateLeft, colordateRight = mergeDate(colorDate)
                    yearLeft, yearRight = mergeDate(year)

                    leftList = []
                    if dateLeft:
                        leftList.append(dateLeft)
                    if colordateLeft:
                        leftList.append(colordateLeft)
                    if yearLeft:
                        leftList.append(yearLeft)
                    rightList = []
                    if dateRight:
                        rightList.append(dateRight)
                    if colordateRight:
                        rightList.append(colordateRight)
                    if yearRight:
                        rightList.append(yearRight)
                    mdateLeft = max(leftList) if leftList else ''
                    mdateRight = min(rightList) if rightList else ''
                    merge_date = mdateLeft + ('-' if mdateLeft or mdateRight else '') + mdateRight

                    vb_desc = set(vb_desc)
                    vb_desc = list(vb_desc)
                    vb_desc = ','.join(vb_desc)

                    cylinder = set(cylinder)
                    cylinder = list(cylinder)
                    cylinder = ','.join(cylinder)

                    transmission = set(transmission)
                    transmission = list(transmission)
                    transmission = ','.join(transmission)

                    drive = set(drive)
                    drive = list(drive)
                    drive = ','.join(drive)

                    diff_mech = set(diff_mech)
                    diff_mech = list(diff_mech)
                    diff_mech = ','.join(diff_mech)

                    energy_type = set(energy_type)
                    energy_type = list(energy_type)
                    energy_type = ','.join(energy_type)
                    power = set(power)
                    power = list(power)
                    power = ','.join(power)
                    vb = ','.join(vb)

                    ssa_codes = []
                    # 发动机排量
                    scylinder = []
                    # 发动机代码
                    svb = []
                    # 发动机排量信息
                    svb_desc = []
                    stransmission = []
                    sdrive = []
                    sdiff_mech = []
                    senergy_type = []
                    spower = []
                    merge_sdate = ''
                    audiStructure = CarsStructureCollectionNew.get_or_none(CarsStructureCollectionNew.cid == audiPart.cid, CarsStructureCollectionNew.mid == audiPart.mid)

                    # sSacodes = getSacode(audiStructure.sa_code)
                    if audiStructure:
                        structure_sa_codes = audiStructure.sa_code or '{}'
                        structure_sa_codes = ujson.loads(structure_sa_codes)
                        for key, value in structure_sa_codes.items():
                            if value:
                                ssa_codes = ssa_codes + value
                        sModel = audiStructure.model.replace('<br/>', '')
                        sDescription = audiStructure.description

                        sModelout = remove_tt(sModel)
                        sDescriptionout = remove_tt(sDescription)

                        if sDescription:
                            for key in s:
                                if key in sDescriptionout:
                                    key = cleanCylinder(key)
                                    scylinder.append(key)
                            for key in pl:
                                if key in sDescription:
                                    svb_desc.append(key)

                        if sModel:
                            for key in bsx:
                                if key in sModelout:
                                    key = cleanTransmission(key)
                                    stransmission.append(key)
                            for key in qd:
                                if key in sModelout:
                                    key = cleanDrive(key)
                                    sdrive.append(key)

                            for key in s:
                                if key in sModelout:
                                    key = cleanCylinder(key)
                                    scylinder.append(key)
                            for key in pl:
                                if key in sModel:
                                    svb_desc.append(key)
                            for key in fdjdm:
                                if key in sModel:
                                    svb.append(key)
                            if 'PR:' in sModel or 'PR-' in sModel or 'pr:' in sModel or 'pr-' in sModel:
                                # 处理part_model中的PR
                                s_pr = re.sub('[\u4e00-\u9fa5]', '', sModel)
                                s_pr = s_pr.replace('PR:', '')
                                s_pr = s_pr.replace('PR-', '')
                                s_pr = s_pr.replace('+', ',')
                                s_pr = s_pr.replace('/', ',')
                                s_pr = s_pr.replace(':', ',')
                                s_pr = s_pr.replace('_', ',')
                                s_pr = s_pr.split(',')
                                for j in s_pr:
                                    ssa_codes.append(j)

                        for i in ssa_codes:
                            if cid.startswith('U'):
                                contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid[1:], CarsSaDesc.sa == i,
                                                                  CarsSaDesc.lang == 'zh',
                                                                  CarsSaDesc.brand_code == audiPart.brand_code)
                            else:
                                contrast = CarsSaDesc.get_or_none(CarsSaDesc.cid == cid, CarsSaDesc.sa == i,
                                                                  CarsSaDesc.lang == 'zh',
                                                                  CarsSaDesc.brand_code == audiPart.brand_code)
                            if not contrast:
                                contrast = CarsSaDesc.get_or_none(CarsSaDesc.sa == i, CarsSaDesc.lang == 'zh', CarsSaDesc.brand_code == audiPart.brand_code)
                            if contrast and contrast.desc:
                                ssaDescout = remove_tt(contrast.desc)
                                # model_desc.append(contrast.desc)
                                if '发动机' in contrast.desc:
                                    # 筛选出sa表desc中的排量信息
                                    for key in pl:
                                        if key in contrast.desc:
                                            svb_desc.append(key)
                                    for key in s:
                                        if key in ssaDescout:
                                            key = cleanCylinder(key)
                                            scylinder.append(key)
                                    for key in fuel:
                                        if key in ssaDescout:
                                            senergy_type.append(key)
                                    for key in glv:
                                        if key in ssaDescout:
                                            key = cleanPower(key)
                                            spower.append(key)

                                # 处理变速器配置
                                if ('变速箱' in contrast.desc or '变速器' in contrast.desc) and ('档' in contrast.desc or '无级' in contrast.desc):
                                    for key in bsx:
                                        if key in ssaDescout:
                                            key = cleanTransmission(key)
                                            stransmission.append(key)

                                # 处理驱动配置
                                for key in qd:
                                    if key in ssaDescout:
                                        key = cleanDrive(key)
                                        sdrive.append(key)

                                # 处理差速器配置
                                if '差速' in contrast.desc or '减速' in contrast.desc:
                                    sdiff_mech.append(contrast.desc)

                        for i in svb:
                            if cid.isdigit():
                                vb_AF = Vb.get_or_none(Vb.aa == str(int(cid)), Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                            elif cid.startswith('U'):
                                vb_AF = Vb.get_or_none(Vb.aa == cid[1:], Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                            else:
                                vb_AF = Vb.get_or_none(Vb.aa == cid, Vb.ab.contains(i), Vb.brand == audiPart.brand_code)
                            if vb_AF:
                                if vb_AF.af:
                                    svb_desc.append(str(int(vb_AF.af) / 100))
                                if vb_AF.ai:
                                    scylinder.append(vb_AF.ai)
                                if vb_AF.ag:
                                    spower.append(vb_AF.ag)

                        sdate, scolordate, syear = audi_do_filter_extra_info(audiStructure.extra_info)
                        sdateLeft, sdateRight = mergeDate(sdate)
                        scolordateLeft, scolordateRight = mergeDate(scolordate)
                        syearLeft, syearRight = mergeDate(syear)
                        # sleftList = [sdateLeft, scolordateLeft, syearLeft]
                        # srightList = [sdateRight, scolordateRight, syearRight]
                        sleftList = []
                        if sdateLeft:
                            sleftList.append(sdateLeft)
                        if scolordateLeft:
                            sleftList.append(scolordateLeft)
                        if syearLeft:
                            sleftList.append(syearLeft)
                        srightList = []
                        if sdateRight:
                            srightList.append(sdateRight)
                        if scolordateRight:
                            srightList.append(scolordateRight)
                        if syearRight:
                            srightList.append(syearRight)
                        msdateLeft = max(sleftList) if sleftList else ''
                        msdateRight = min(srightList) if srightList else ''
                        merge_sdate = msdateLeft + ('-' if msdateLeft or msdateRight else '') + msdateRight

                    svb_desc = set(svb_desc)
                    svb_desc = list(svb_desc)
                    svb_desc = ','.join(svb_desc)

                    scylinder = set(scylinder)
                    scylinder = list(scylinder)
                    scylinder = ','.join(scylinder)

                    stransmission = set(stransmission)
                    stransmission = list(stransmission)
                    stransmission = ','.join(stransmission)

                    sdrive = set(sdrive)
                    sdrive = list(sdrive)
                    sdrive = ','.join(sdrive)

                    sdiff_mech = set(sdiff_mech)
                    sdiff_mech = list(sdiff_mech)
                    sdiff_mech = ','.join(sdiff_mech)

                    senergy_type = set(senergy_type)
                    senergy_type = list(senergy_type)
                    senergy_type = ','.join(senergy_type)

                    spower = set(spower)
                    spower = list(spower)
                    spower = ','.join(spower)

                    svb = ','.join(svb)

                    unit = {'pid': audiPart.pid, 'cid': audiPart.cid, 'mid': audiPart.mid, 'brand_code': audiPart.brand_code,
                            'standard_label': stand_label, 'engine_code': vb,
                            'cylinder': cylinder, 'transmission': transmission, 'drive': drive, 'diff_mech': diff_mech,
                            'displacement': vb_desc, 'pid_date': merge_date, 'energy_type': energy_type, 'power': power,
                            'group_engine_code': svb, 'group_cylinder': scylinder, 'group_transmission': stransmission,
                            'group_drive': sdrive, 'group_diff_mech': sdiff_mech, 'group_displacement': svb_desc,
                            'group_date': merge_sdate, 'group_energy_type': senergy_type, 'group_power': spower}
                    print(unit)
                    items.append(unit)

        df = pd.DataFrame(items)
        df['pid'] = df['pid'].astype('str')
        df.to_csv('./export/vwag_parts'+i+'.csv', mode='a', index=False)

if __name__ == '__main__':
    print("父进程开始...")
    pp = Pool(5)
    for i in range(5):
        pp.apply_async(DealParts, args=(i,))
    pp.close()
    pp.join()
    print("父进程结束...")